package org.logan.sample.web.base.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.logan.sample.web.base.engine.WebSampleInit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

public class ServletExceptionResolver implements HandlerExceptionResolver {
	private final Logger logger = LoggerFactory.getLogger(WebSampleInit.class);

	@Override
	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
			Exception ex) {
		ex.printStackTrace();
		logger.error("500 Internal Server Error", ex);
		response.setStatus(500);
		ModelAndView model = new ModelAndView("errors/error_500.html");
		model.addObject("r", 0);
		model.addObject("m", "500 Internal Server Error");
		model.addObject("debug", "debug");
		return model;
	}
}
